<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>猎头公司信息</title>  
</head>
<body>
<div class="ui segment" id="n-page">

        <div class="ui segment" id="n-content">
            <form class="ui form">
             <div class="field">
                 <label><span style="color: red">*</span>公司名称</label>
                    <div class="ui input">
                    <input type="text" name="companyname" id="companyname" value="${company.name}" disabled>
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>联系人</label>
                    <div class="ui input">
                        <input type="text" name="companycontact" id="companycontact" value="${company.contact}" placeholder="请输入公司联系人">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>联系电话</label>
                    <div class="ui input">
                        <input type="text" name="companyphone" id="companyphone" value="${company.phone}" placeholder="请输入公司联系电话">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>公司地址</label>
                    <div class="ui input">
                        <input type="text" name="companyaddress" id="companyaddress" value="${company.address}" placeholder="请输入公司地址">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>组织机构代码</label>
                    <div class="ui input">
                        <input type="text" name="orgcode" id="orgcode" value="${company.orgnizationCode}" placeholder="请输入组织机构代码">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>营业执照编码</label>
                    <div class="ui input">
                        <input type="text" name="bizcode" id="bizcode" value="${company.licenseCode}" placeholder="请输入营业执照编码" disabled>
                    </div>
                </div>                      
                <input type="hidden" name="hunterid" id="hunterid" value="${hunter.id}"/>
            </form>        
        </div>
        <!--
        <div class="ui segment" id="btn-next2">
            <div class="fluid ui button" id="next">下一步</div>
        </div>
        -->
        <div class="ui center aligned segment" id="choice-buttons"> 
            <div class="two ui buttons"> 
                <div class="ui button active dog" id="next">下一步</div> 
                <div class="ui button active dog" id="closeit">回首页</div> 
            </div>
        </div>

</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu',
        'closeWindow']  
});

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }

            if($(this).attr('id') == 'next') {

                var hunterid       = $("#hunterid").val();
                var companycontact = $("#companycontact").val();
                var companyphone   = $("#companyphone").val();
                var companyname    = $("#companyname").val();
                var companyaddress = $("#companyaddress").val();
                var orgcode  = $("#orgcode").val();
                var bizcode  = $("#bizcode").val();

                if(!companyname) {
                    alert("您必须输入公司名称");
                    return false;
                }

                if(!companycontact || companycontact == "" || companycontact.length > 40) {
                    alert("您必须输入合格的公司联系人");
                    return false;
                }
                if(!companyphone || companyphone=="" || companyphone.length <5 || companyphone.length>18) {
                    alert("您必须输入合格的公司电话");
                    return false;
                }
                var regEx1 = /^([0-9]|[\-])+$/g;
                if (!companyphone.match(regEx1)) {
                    alert("您必须输入合格的公司电话");
                    return false;
                }
                if(!companyaddress || companyaddress=="" || companyaddress.length > 50) {
                    alert("您必须输入合格的公司地址");
                    return false;
                }
                if(!orgcode || orgcode=="" || orgcode.length > 20) {
                    alert("您必须输入合格的公司组织代码");
                    return false;
                }
                if(!bizcode || bizcode=="" || bizcode.length >20) {
                    alert("您必须输入合格的营业执照编码");
                    return false;
                }

                $(this).addClass('disabled');
                var that = this;

                var postUrl = '${ctx}/wechat/hunterCompany/create1_2.do';
                var param = {};
                param['companycontact']  = companycontact;
                param['companyname'] = companyname;
                param['companyphone'] = companyphone;
                param['companyaddress'] = companyaddress;
                param['hunterid']     = hunterid;
                param['orgcode']     = orgcode;
                param['bizcode']     = bizcode;

                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(response){ 
                        if(response.errorcode=="0"){
                            var companyid = response.data;
                            location.href = '${ctx}/wechat/hunter/toUploadFile.page?hunterId='+hunterid;
                        }else{
                            alert(response.msg); 
                            $(that).removeClass('disabled');
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                        $(that).removeClass('disabled');
                    } 
                });

                /*
                var companyid = $("#companyid").val();
                var hunterid  = $("#hunterid").val();
                var companycontact = $("#companycontact").val();
                var companyphone   = $("#companyphone").val();
                var companyname    = $("#companyname").val();
                var companyaddress = $("#companyaddress").val();
                var orgcode  = $("#orgcode").val();
                var bizcode  = $("#bizcode").val();
                var companyname2 = "${hunter.companyName}";

                if(!companycontact) {
                    alert("您必须输入公司联系人");
                    return false;
                }
                if(!companyphone) {
                    alert("您必须输入公司电话");
                    return false;
                }
                if(!companyaddress) {
                    alert("您必须输入公司地址");
                    return false;
                }
                if(!orgcode) {
                    alert("您必须输入公司组织代码");
                    return false;
                }
                if(!bizcode ) {
                    alert("您必须输入营业执照编码");
                    return false;
                }

                var postUrl = '${ctx}/wechat/hunterCompany/create.do';
                var param = {};
                param['companycontact']  = companycontact;
                param['companyid']   = companyid;
                param['companyname'] = companyname;
                param['companyphone'] = companyphone;
                param['companyaddress'] = companyaddress;
                param['hunterid']     = hunterid;
                param['orgcode']     = orgcode;
                param['bizcode']     = bizcode;

                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(response){ 
                        if(response.errorcode=="200"){
                            var companyid = response.data;
                            location.href = '${ctx}/wechat/hunter/toUploadFile.page?hunterId='+hunterid;
                        }else{
                            alert(response.msg); 
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
                });
                */
               
            }
        } 
    };

    $(document).ready(function() {
        wx.ready(function() {  
            $('.button').on('click', handler.activate);
            $('.dropdown').dropdown({
                fullTextSearch:true,
            });

            wx.hideOptionMenu();
            
        });
    });

</script>
</body>
</html>